<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Vue源码试</title>
</head>
<body>
  <div id="app">
    <div>{{msg}}</div>
    <p v-for="item in list" :key="item.id">{{item.info}}</p>
    <button @click="addItem">添加一项</button>
    <p>---------------------computed---------------------------</p>
    <p>{{getNewTest}}</p>
    <button @click="changeTest">改变test</button>
    <p>{{formatPrice}}</p>
    <button @click="changePrice">改变price</button>
    <br>
    <p>-------------------------------------</p>
    <button @click="caseClick">实例方法</button>
  </div>

  <script src="../dist/vue.js"></script>
  <script>
    Vue.filter('my-filter', function (value) {})

    new Vue({
      el: '#app',
      data: {
        msg: 'Hello Vue',
        age: 18,
        userName: '张三',
        list: [
          {
            id: '1',
            info: '这是1'
          }
        ],
        info: {
          size: 'small'
        },
        test: 'test',
        price: 10
      },
      methods: {
        addItem() {
          const item = {
            id: JSON.stringify(this.list.length),
            info: `这是${JSON.stringify(this.list.length)}`
          }
          this.list.push(item)
        },
        userNameChange() {},
        changeTest() {
          this.test = 'newTest'
        },
        changePrice() {
          this.price = 20
        },
        // 实例方法
        caseClick() {
          console.log(this.$data)
        }
      },
      watch: {
        msg: {
          handler(newName, oldName) {
            console.log(newName)
          },
          immediate: true
        },
        age(newName, oldName) {},
        userName: 'userNameChange',
        'info.size'() {
          
        } 
      },
      computed: {
        getNewTest() {
          return `hello, ${this.test}`
        },
        formatPrice: {
          get() {
            return this.price.toFixed(2)
          },
          set(val) {}
        }
      }
    })
  </script>
</body>
</html>